package com.rimi.service.impl;

import com.rimi.bean.MenuAddress;
import com.rimi.bean.MenuType;
import com.rimi.cache.AdminCache;
import com.rimi.dao.MenuTypeDao;
import com.rimi.service.MenuAddressService;
import com.rimi.service.MenuTypeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * InnoDB free: 11264 kB 服务实现类
 * </p>
 *
 * @author sky
 * @since 2018-06-06
 */
@Service
public class MenuTypeServiceImpl extends ServiceImpl<MenuTypeDao, MenuType> implements MenuTypeService {

    @Autowired
    private MenuTypeService menuTypeService;
    @Autowired
    private MenuTypeDao menuTypeDao;

    @Autowired
    private AdminCache adminCache;

    /*从redis查询类型菜单列表*/
    public List<MenuType> getMenuTypeList(){
        List<MenuType> MenuType = adminCache.getCacheList("MenuType", com.rimi.bean.MenuType.class);
        //缓存中是否有数据
        if(MenuType!=null&&!MenuType.isEmpty()){
            return MenuType;
        }
        //如果有数据
        List<MenuType> MenuType1 =menuTypeService.selectList(null);
        //将查询结果缓存到redis中
        adminCache.addCacheList("MenuType", MenuType1);
        return MenuType1;
    }

    @Override
    public List getVideoTypeMenuListByVideoId(Integer videoId) {
        return menuTypeDao.getVideoTypeMenuListByVideoId(videoId);
    }


    //通过menuName查询menuType
    @Override
    public List getMenuTypeByMenuName(String menuName) {
        List cacheList = adminCache.getCacheList(menuName+"MenuType", MenuType.class);
        if (cacheList!=null&&!cacheList.isEmpty()){
            return cacheList;
        }
        List menuTypeByMenuName = menuTypeDao.getMenuTypeByMenuName(menuName);
        adminCache.addCacheList(menuName+"MenuType", menuTypeByMenuName);
        return menuTypeByMenuName;
    }


}
